package cqgans.app.sunao.com.cqgans.adapter;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import cqgans.app.sunao.com.cqgans.bean.Product;
import cqgans.app.sunao.com.cqgans.common.AppConstant;
import cqgans.app.sunao.com.cqgans.utils.xUtilsImageUtils;
import cqgans.app.sunao.com.cqgansnew.R;


/**
 * Created by sunao on 2017/6/12.
 */

public class ProductAdapter extends BaseListAdapter<Product> {

    public ProductAdapter(Context context) {
        this.context = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.item_product, parent,false);
            holder.product_img = (ImageView) convertView.findViewById(R.id.product_img1);
            holder.product_title = (TextView) convertView.findViewById(R.id.product_title);
            holder.product_desc = (TextView) convertView.findViewById(R.id.product_desc);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Product u =  getItems().get(position);
        xUtilsImageUtils.display(holder.product_img , AppConstant.URL+u.getImgurl());
        holder.product_title.setText(u.getTitle());
        holder.product_desc.setText(Html.fromHtml(u.getDescs()));
        return convertView;
    }

    class ViewHolder {
        ImageView product_img;
        TextView product_title;
        TextView product_desc;

    }
}
